/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects.coders;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.Date;

import org.latestbit.smartobjects.exceptions.DataTypesCoderException;
import org.latestbit.smartobjects.io.ResizableByteBuffer;

/**
 * Interface provides access to binary network 
 * protocolencoder/decoder implementation
 * @author abdulla-a
 */
public interface IDataTypesCoder {
	
	public void encodeByte(byte value, ResizableByteBuffer buffer) 
		throws  DataTypesCoderException, BufferUnderflowException;
	public byte decodeByte(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeUByte(byte value, ResizableByteBuffer buffer) 
		throws  DataTypesCoderException, BufferUnderflowException;
	public byte decodeUByte(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeInt16(short value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public short decodeInt16(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeUInt16(short value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public short decodeUInt16(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeInt32(int value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeInt32(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeUInt32(int value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeUInt32(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeInt64(long value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public long decodeInt64(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeUInt64(long value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public long decodeUInt64(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeBigInteger(BigInteger value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public BigInteger decodeBigInteger(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeBigDecimal(BigDecimal value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public BigDecimal decodeBigDecimal(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeFloat(float value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public float decodeFloat(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeDouble(double value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public double decodeDouble(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeString(String value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public String decodeString(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeWString(String value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public String decodeWString(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeChar(char value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public char decodeChar(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeWChar(char value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public char decodeWChar(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeBoolean(boolean value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public boolean decodeBoolean(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeDateTime(Date value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public Date decodeDateTime(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeByteArray(byte[] value, ResizableByteBuffer buffer) 
		throws  DataTypesCoderException, BufferUnderflowException;
	public byte[] decodeByteArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeUByteArray(byte[] value, ResizableByteBuffer buffer) 
		throws  DataTypesCoderException, BufferUnderflowException;
	public byte[] decodeUByteArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeInt16Array(short[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public short[] decodeInt16Array(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	
	public void encodeUInt16Array(short[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public short[] decodeUInt16Array(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeInt32Array(int[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public int[] decodeInt32Array(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeUInt32Array(int[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public int[] decodeUInt32Array(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeInt64Array(long[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public long[] decodeInt64Array(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeUInt64Array(long[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public long[] decodeUInt64Array(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeBigIntegerArray(BigInteger[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public BigInteger[] decodeBigIntegerArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeBigDecimalArray(BigDecimal[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public BigDecimal[] decodeBigDecimalArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeFloatArray(float[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public float[] decodeFloatArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeDoubleArray(double[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public double[] decodeDoubleArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeStringArray(String[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public String[] decodeStringArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	
	public void encodeWStringArray(String[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public String[] decodeWStringArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	
	public void encodeCharArray(char[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public char[] decodeCharArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	
	public void encodeWCharArray(char[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public char[] decodeWCharArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	
	public void encodeBooleanArray(boolean[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public boolean[] decodeBooleanArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeDateTimeArray(Date[] value, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public Date[] decodeDateTimeArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	
	public void encodeObjectArray(int arraySize, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeObjectArray(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public int encodeObjectListBegin( ResizableByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeObjectListBegin(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeObjectListEnd(int beginPos, int count, ResizableByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;
	public void decodeObjectListEnd(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeObjectMap(int mapSize, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeObjectMap(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeFloatingLength(int len, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public int decodeFloatingLength(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeNull(ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public boolean decodeNull(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;

	public void encodeStructureDataTypeBegin(ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public boolean decodeStructureDataTypeBegin(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeStructureDataTypeEnd(ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public void decodeStructureDataTypeEnd(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public int encodeNamedDataPartBegin ( String structurePartName, ResizableByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeNamedDataPartBegin ( String structurePartName, ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeNamedDataPartEnd ( int beginPos, ResizableByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;
	public void decodeNamedDataPartEnd ( int beginPos, ByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;	

	public void encodeEnumDataType(int selectedIndex, ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;	
	public int decodeEnumDataType(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeExceptionDataTypeBegin(ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public boolean decodeExceptionDataTypeBegin(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeExceptionDataTypeEnd(ResizableByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	public void decodeExceptionDataTypeEnd(ByteBuffer buffer)
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public int encodeEncryptedDataTypeBegin( ResizableByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;
	public int decodeEncryptedDataTypeBegin( ByteBuffer buffer )
		throws  DataTypesCoderException, BufferUnderflowException;
	
	public void encodeEncryptedDataTypeEnd( int beginPos, ResizableByteBuffer buffer )
		throws DataTypesCoderException, BufferUnderflowException;
	public void decodeEncryptedDataTypeEnd(ByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	
	public void encodeObjectType ( String className, ResizableByteBuffer buffer )
		throws DataTypesCoderException, BufferUnderflowException;
	public String decodeObjectType( ByteBuffer buffer ) 
		throws DataTypesCoderException, BufferUnderflowException;
	
	public int encodeChoiceDataTypeBegin(ResizableByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	public int decodeChoiceDataTypeBegin(ByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	
	public void encodeChoiceSelectedField(String selectedField, ResizableByteBuffer buffer) 
		throws DataTypesCoderException,	BufferUnderflowException;	
	public String decodeChoiceSelectedField(ByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	
	public void encodeChoiceDataTypeEnd(int beginPos, ResizableByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	public void decodeChoiceDataTypeEnd(int beginPos, ByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;

	public void encodeGrammar(ResizableByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	public void decodeGrammar(ByteBuffer buffer)
		throws DataTypesCoderException, BufferUnderflowException;
	public void reset();
}
